package com.qf.anli.interceptors;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        //对资源做拦截判断 -- 是否登录
        Object userInfo = request.getSession().getAttribute("userInfo");
        if(userInfo == null){
            //跳转到登录页面
            response.sendRedirect("/login.html");
            return false;
        }
        return true;
    }
}
